home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.06 Oct 92 / One-Application Patches / InvertRect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-08  |  1.6 KB  |  81 lines  |  [TEXT/KAHL]

  1. /*    --------------------------------------------
  2.         patch InvertRect.c
  3.         
  4.         THINK C "Set Project Type..." settings:
  5.         code resource, type 'OAPn', ID 1001,
  6.         custom header, preloaded and locked,
  7.         file type 'rsrc', file creator 'RSED'.
  8.         --------------------------------------------
  9. */
  10. #include <Traps.h>
  11. #include "defs.h"
  12.  
  13. void main(void);
  14. void My_InverRect( void );
  15.  
  16. /* -------- global variables ---------- */
  17. long    Old_InverRect = NIL;
  18.  
  19. void main(void)
  20. {
  21.     long            save_A4;
  22.     
  23.     asm {
  24.         move.L        A4, save_A4
  25.         LEA                main, A4
  26.     }
  27.  
  28.     if (Old_InverRect == NIL)
  29.     {
  30.         Old_InverRect = GetToolTrapAddress(
  31.                     _InverRect );
  32.         SetToolTrapAddress( (long)My_InverRect,
  33.                     _InverRect );
  34.     }
  35.     
  36.     asm {
  37.         move.L        save_A4, A4
  38.     }
  39. }
  40.  
  41.  
  42. /*    ---------------------------------------------
  43.         My_InverRect        Watch for the insertion point
  44.                                         to be drawn, and record its
  45.                                         horizontal coordinate.
  46.         ---------------------------------------------
  47. */
  48. void My_InverRect( void )
  49. {
  50.     Rect                *rect;
  51.     Wrap_info    **info;
  52.     
  53.     asm {
  54.         movem.L        a0-a5/d0-d7, -(SP); save registers
  55.         LEA                main, A4                ; access to globals
  56.         move.L        8(A6), rect
  57.     }
  58.     
  59.     if ( rect->right - rect->left == 1 )
  60.     {
  61.         info = (Wrap_info **)
  62.                             GetResource('OAP1', 128);
  63.         (**info).last_insertion_point = rect->right;
  64.     }
  65.     
  66.     /*
  67.         The following code restores all registers and
  68.         jumps to the saved trap address.  It relies
  69.         on there being at least 4 bytes on the stack
  70.         frame, which can be trashed by moving the
  71.         saved A6 down.  Bear in mind that THINK C will
  72.         insert UNLK A6 and RTS instructions afterward.
  73.     */
  74.     asm {
  75.         move.L        (A6), -4(A6)
  76.         move.L        Old_InverRect, (A6)
  77.         subQ            #4, A6
  78.         movem.L        (SP)+, A0-A5/D0-D7
  79.     }
  80. }
  81.